// Copyright (C) ustc9703
// All rights reserved.
// 
// Author : dengxinguo
// Date   : 2004-12-1

#include "stdafx.h"
#include ".\diskbox.h"
#include "mainuiman.h"
#include "roompage.h"
#include "findfilewnd.h"

//##ModelId=44C4B5E30203
void CJoyDiskBoxItem::CM_Draw(Graphics& graph)
{
    CJoyDiskBox* DiskBox = GetDiskBox();
    Color textColor, backColor;
    if(IsSel())
    {
        backColor = DiskBox->m_selBackColor;
        textColor = DiskBox->m_selTextColor;
    }
    else
    {
        backColor = DiskBox->m_itemBackColor;
        textColor = DiskBox->m_itemTextColor;
    }

    SolidBrush backBrush(backColor);
    graph.FillRectangle(&backBrush, 1, 1, m_area.Width()-2, m_area.Height()-2);

    StringFormat sf;
    sf.SetLineAlignment(StringAlignmentCenter);

    SolidBrush txBrush(textColor);

    FontFamily fam(DiskBox->m_textFace);
    Font font(&fam, (REAL)DiskBox->m_textSize, FontStyleRegular, UnitPixel);

    graph.DrawString(
        m_diskName, m_diskName.GetLength(),
        &font,
        RectF((REAL)DiskBox->m_textMargin, (REAL)0, (REAL)m_area.Width(), (REAL)m_area.Height()),
        &sf, &txBrush);
}

//##ModelId=44C4B5E30262
CJoyDiskBox::CJoyDiskBox(void)
{
}
//##ModelId=44C4B5E30264
CJoyDiskBox::CJoyDiskBox(HWND hwnd,UINT msgid)
{
	m_parentwnd=hwnd;
	m_msgid=msgid;
}

//##ModelId=44C4B5E30272
CJoyDiskBox::~CJoyDiskBox(void)
{
}

//##ModelId=44C4B5E30233
void CJoyDiskBox::CM_SelItem(CJoyComboItem* item)
{
	::SendMessage(m_parentwnd,m_msgid,(WPARAM)&(item->m_name),NULL);
    __super::CM_SelItem(item);
}

//##ModelId=44C4B5E30226
void CJoyDiskBox::CM_LoadSkin(CJoyXmlElement* pSkinElem)
{
    __super::CM_LoadSkin(pSkinElem);

    m_frameColor.SetValue(pSkinElem->ReadIntX("frame_color", m_frameColor.GetValue()));
    m_selTextColor.SetValue(pSkinElem->ReadIntX("sel_text_color", m_selTextColor.GetValue()));
    m_selBackColor.SetValue(pSkinElem->ReadIntX("sel_back_color", m_selBackColor.GetValue()));
    m_itemBackColor.SetValue(pSkinElem->ReadIntX("item_back_color", m_itemBackColor.GetValue()));
    m_itemTextColor.SetValue(pSkinElem->ReadIntX("item_text_color", m_itemTextColor.GetValue()));
    m_textMargin = pSkinElem->ReadIntD("text_margin", m_textMargin);
}

//##ModelId=44C4B5E30223
void CJoyDiskBox::CM_Draw(Graphics& graph)
{
    Pen frm(m_frameColor);
    graph.DrawRectangle(&frm, 0, 0, m_area.Width()-1, m_area.Height()-1);

    SolidBrush back(m_backColor);
    graph.FillRectangle(&back, 1, 1, m_area.Width()-2, m_area.Height()-2);

    if(m_selItem == NULL)
    {
        return;
    }

    CJoyDiskBoxItem* item = (CJoyDiskBoxItem*)m_selItem;

    StringFormat sf;
    sf.SetLineAlignment(StringAlignmentCenter);

    SolidBrush txBrush(m_textColor);

    FontFamily fam(m_textFace);
    Font font(&fam, (REAL)m_textSize, FontStyleRegular, UnitPixel);

    graph.DrawString(
        item->m_diskName, item->m_diskName.GetLength(),
        &font,
        RectF((REAL)m_textMargin, (REAL)0, (REAL)m_area.Width(), (REAL)m_area.Height()),
        &sf, &txBrush);
}
